﻿using UnityEngine;
using System.Collections;

public class InstanceThings : MonoBehaviour {

	public GameObject t_Numbers;
	public static int countNumbers = 1;//contador para ir del 1 al 9 con el texto
	public GameObject g_Sphere;
	public Transform back; // para calcular donde los voy a instanciar

	public float f_timerIns;
	private float fp_TimerIns; //time private instance

	private Vector3 pos; // posicion donde aparece lo instanciado

	private GameObject gameObj; // instanceo aca y seteo como parent al level

	void Start () {
		//asi empieza de toqe
		fp_TimerIns = 0.5f;
	}
	
	// Update is called once per frame
	void Update () {
		fp_TimerIns -= Time.deltaTime;

		if (fp_TimerIns < 0)
		{
			int i = Random.Range (0,2);
			if (i == 0)
			{
				RandomPos();
				gameObj = Instantiate(t_Numbers,pos,t_Numbers.transform.localRotation) as GameObject;
				//gameObj.transform.parent = this.transform;
			}
			if (i == 1 )
			{
				RandomPos();
				gameObj = Instantiate(g_Sphere,pos,g_Sphere.transform.localRotation) as GameObject;
				//gameObj.transform.parent = this.transform;
			}
			gameObj.transform.parent = this.transform;
			fp_TimerIns = f_timerIns;	
		}
	}


	void RandomPos()
	{
		pos = new Vector3(Random.Range(-back.localScale.x/2,back.localScale.x/2),
		                  Random.Range(-back.localScale.y/2,back.localScale.y/2),
		                 0);
	}
}
